import { SystemMsg, SystemProjectJoinMsg } from '@entity/system_msg';
import { Component, Prop, Vue } from 'vue-property-decorator';
import SystemMsgModel from '@message/system/model/Index.vue';
import { User } from '@entity/user';
import { JoinProjectRequest, JoinProjectResponse } from '@entity/join_project'
import { ProjectTag } from '@entity/project';
import axios from '@axios/websocket'

@Component({
    components: {
        SystemMsgModel
    }
})
export class JoinProjectRequestView extends Vue {

    @Prop({
        default: () => new SystemMsg()
    })
    /** 系统消息 */
    private msg: SystemMsg;

    created() {
        console.log(this.msg)
    }

    /** 是否显示对话框 */
    private display: boolean = false;
    
    /** 
     * 获取系统消息中的项目申请信息
     */
    getMsg(): SystemProjectJoinMsg<JoinProjectRequest> {
        return this.msg.data
    }

    /** 
     * 获取申请
     */
    getRequest(): JoinProjectRequest {
        return this.getMsg().data;
    }

    /**
     * 获取申请职位的 id
     */
    private getTagId(): number {
        let positions: Array<ProjectTag> = this.$store.getters.project(this.getRequest().id).positions;
        let result = -1;
        positions.forEach((tag: ProjectTag) => {
            if (tag.tag === this.getRequest().tag) {
                result = tag.id;
                return;
            }
        })
        return result;
    }

    /** 
     * 处理申请, 做出反馈
     * @param flag 处理结果
     */
    private doResponse(flag: boolean) {
        let user: User = this.$store.getters.user(this.getMsg().userId);
        let response: JoinProjectResponse = new JoinProjectResponse(this.getRequest().id, this.getRequest().name, this.getTagId(), flag)
        axios.join.response(user, response);
    }
}